package cn.edu.scau.cmi.zhangmingxing.client;

import java.util.Scanner;

import cn.edu.scau.cmi.zhangmingxing.abstractFactory.domainAbstractClass.Meat;
import cn.edu.scau.cmi.zhangmingxing.abstractFactory.factory.AbstractFactory;
import cn.edu.scau.cmi.zhangmingxing.factory.BeefFactory;
import cn.edu.scau.cmi.zhangmingxing.factory.ChickenFactory;
import cn.edu.scau.cmi.zhangmingxing.factory.MeatFactory;
import cn.edu.scau.cmi.zhangmingxing.factory.PorkFactory;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class AbstractFactoryClient extends Application {
	public void start(Stage primaryStage) {
		primaryStage.setTitle("AbstractFactory");
		Group root = new Group();
		HBox btn = new HBox();
		btn.setLayoutX(10);
		btn.setLayoutY(10);
		TextArea area = new TextArea();
		area.setLayoutX(10);
		area.setLayoutY(45);
		area.setMaxHeight(240);
		area.setMaxWidth(550);
		area.setEditable(false);
		Button btn1 = new Button();
		btn1.setText("Wens");
		Button btn2 = new Button();
		btn2.setText("Tianbang");
		Button btn3 = new Button();
		btn3.setText("Aonong");
		btn.setSpacing(40);
		btn.setAlignment(Pos.CENTER);
		btn.getChildren().addAll(btn1, btn2, btn3);
		root.getChildren().addAll(area, btn);
		Scene scene = new Scene(root, 600, 300, Color.rgb(0, 0, 0, 0));
		primaryStage.setScene(scene);
		primaryStage.show();
		AbstractFactory factory = null;
		String productType = null;
		btn1.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent event) {
				String brandKind = "Wens";
				Stage stage = new Stage();
				stage.setTitle("product");
				Group root = new Group();
				HBox btn = new HBox();
				btn.setLayoutX(10);
				btn.setLayoutY(10);
				Button btn1 = new Button();
				btn1.setText("pork");
				Button btn2 = new Button();
				btn2.setText("beef");
				Button btn3 = new Button();
				btn3.setText("chicken");
				btn.setSpacing(40);
				btn.setAlignment(Pos.CENTER);
				btn.getChildren().addAll(btn1, btn2, btn3);
				root.getChildren().addAll(btn);
				Scene scene = new Scene(root);
				stage.setScene(scene);
				stage.show();
				btn1.setOnAction(new EventHandler<ActionEvent>() {
					public void handle(ActionEvent event) {
						String productType = "pork";
						AbstractFactory factory = AbstractFactory.getFactory(brandKind);
						Meat meat = factory.getPork();
						area.appendText(meat.cook() + "\n");
					}
				});
				btn2.setOnAction(new EventHandler<ActionEvent>() {
					public void handle(ActionEvent event) {
						String productType = "beef";
						AbstractFactory factory = AbstractFactory.getFactory(brandKind);
						Meat meat = factory.getBeef();
						area.appendText(meat.cook() + "\n");
					}
				});
				btn3.setOnAction(new EventHandler<ActionEvent>() {
					public void handle(ActionEvent event) {
						String productType = "chicken";
						AbstractFactory factory = AbstractFactory.getFactory(brandKind);
						Meat meat = factory.getChicken();
						area.appendText(meat.cook() + "\n");
					}
				});
			}
		});
		btn2.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				String brandKind = "Tianbang";
				Stage stage = new Stage();
				stage.setTitle("product");
				Group root = new Group();
				HBox btn = new HBox();
				btn.setLayoutX(10);
				btn.setLayoutY(10);
				Button btn1 = new Button();
				btn1.setText("pork");
				Button btn2 = new Button();
				btn2.setText("beef");
				Button btn3 = new Button();
				btn3.setText("chicken");
				btn.setSpacing(40);
				btn.setAlignment(Pos.CENTER);
				btn.getChildren().addAll(btn1, btn2, btn3);
				root.getChildren().addAll(btn);
				Scene scene = new Scene(root);
				stage.setScene(scene);
				stage.show();
				btn1.setOnAction(new EventHandler<ActionEvent>() {
					public void handle(ActionEvent event) {
						String productType = "pork";
						AbstractFactory factory = AbstractFactory.getFactory(brandKind);
						Meat meat = factory.getPork();
						area.appendText(meat.cook() + "\n");
					}
				});
				btn2.setOnAction(new EventHandler<ActionEvent>() {
					public void handle(ActionEvent event) {
						String productType = "beef";
						AbstractFactory factory = AbstractFactory.getFactory(brandKind);
						Meat meat = factory.getBeef();
						area.appendText(meat.cook() + "\n");
					}
				});
				btn3.setOnAction(new EventHandler<ActionEvent>() {
					public void handle(ActionEvent event) {
						String productType = "chicken";
						AbstractFactory factory = AbstractFactory.getFactory(brandKind);
						Meat meat = factory.getChicken();
						area.appendText(meat.cook() + "\n");
					}
				});
			}
		});
		btn3.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				String brandKind = "Aonong";
				Stage stage = new Stage();
				stage.setTitle("product");
				Group root = new Group();
				HBox btn = new HBox();
				btn.setLayoutX(10);
				btn.setLayoutY(10);
				Button btn1 = new Button();
				btn1.setText("pork");
				Button btn2 = new Button();
				btn2.setText("beef");
				Button btn3 = new Button();
				btn3.setText("chicken");
				btn.setSpacing(40);
				btn.setAlignment(Pos.CENTER);
				btn.getChildren().addAll(btn1, btn2, btn3);
				root.getChildren().addAll(btn);
				Scene scene = new Scene(root);
				stage.setScene(scene);
				stage.show();
				btn1.setOnAction(new EventHandler<ActionEvent>() {
					public void handle(ActionEvent event) {
						String productType = "pork";
						AbstractFactory factory = AbstractFactory.getFactory(brandKind);
						Meat meat = factory.getPork();
						area.appendText(meat.cook() + "\n");
					}
				});
				btn2.setOnAction(new EventHandler<ActionEvent>() {
					public void handle(ActionEvent event) {
						String productType = "beef";
						AbstractFactory factory = AbstractFactory.getFactory(brandKind);
						Meat meat = factory.getBeef();
						area.appendText(meat.cook() + "\n");
					}
				});
				btn3.setOnAction(new EventHandler<ActionEvent>() {
					public void handle(ActionEvent event) {
						String productType = "chicken";
						AbstractFactory factory = AbstractFactory.getFactory(brandKind);
						Meat meat = factory.getChicken();
						area.appendText(meat.cook() + "\n");
					}
				});
			}
		});
//		System.out.println("Please select which brand you want to buy: Wens, Tianbang or aonong???");
//		Scanner scanner = new Scanner(System.in);  
//		String brandKind = scanner.next();  
//		AbstractFactory factory=null;
//		factory=AbstractFactory.getFactory(brandKind);
//		
////		（2）选择产品
//		
//		System.out.println("Please select which product you want to buy: cellphone, pad or watch???");
////		Scanner scanner = new Scanner(System.in);  
//		String productType = scanner.next();  
//		Meat electronics=null;
//		switch(productType) {
//		case "pork": electronics=factory.getPork();break;
//		case "beef": electronics=factory.getBeef();break;
//		case "chicken": electronics=factory.getChicken();break;
//		default:System.out.println("sorry, your input is not correct");
//		
//		}
//		if(electronics!=null) {
//			electronics.cook();
//		}
//		scanner.close();
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// (1) 选择品牌

		launch(args);

//				
//				// （1）获取工厂
//				
//				AbstractFactory factory = AbstractFactory.getFactory("apple");
		//
//				// (2)获取对象
//				Pad product = factory.createPad();
////				（3）对象执行功能
//				product.play();

	}
}
